home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / XMSLB17.ARJ / XMS.C < prev    next >
C/C++ Source or Header  |  1991-06-11  |  5KB  |  144 lines

  1. /* $Id: xms.c 1.3 91/06/11 10:00:53 explorer Exp Locker: explorer $ */
  2.  
  3. /*
  4.     This program will determine whether or not an XMS driver is
  5.     installed, and will return several statistics about it if
  6.     a driver is found.
  7.  
  8.     It will also test most of the XMSLIB routines.
  9.  
  10.     USE AT YOUR OWN RISK
  11. */
  12.  
  13. #include <stdio.h>
  14. #include <stdlib.h>
  15. #include <dos.h>
  16. #include "xmslib.h"
  17.  
  18.  
  19. int main()
  20. {
  21.     unsigned char error;    /* error code returned be most routines */
  22.     unsigned int freemem, totmem;   /* memory stats */
  23.     unsigned int ver_proto, ver_driver, hma_avail;  /* version stats */
  24.     unsigned int state; /* state of the A20 line. */
  25.     unsigned int handle;    /* EMB handle allocated */
  26.     unsigned long address;  /* pointer to EMB.  Note:  this is a 32bit linear    */
  27.                         /* address, so it cannot be used directly.           */
  28.     unsigned char locks, fhandles;  /* locks on the handle, and handles free */
  29.     unsigned int blength;   /* size of the block (for info request) */
  30.     unsigned int maxumb, segaddr;   /* for UMB request.  (not on MY machine!) */
  31.     char    message[30]  = "This be a test.";   /* for extended mem move    */
  32.     char    message2[30] = "xxxxxxxxxxxxxxx";   /*  "     "      "   "      */
  33.  
  34.     struct EMMMoveStruct moverec; /* also for extended memory move          */
  35.  
  36.  
  37.     printf("Compiled with the %s memory model\n",
  38. #if defined(__HUGE__)
  39.     "HUGE"
  40. #else
  41. #if defined(__LARGE__)
  42.     "LARGE"
  43. #else
  44. #if defined(__MEDIUM__)
  45.     "MEDIUM"
  46. #else
  47. #if defined(__COMPACT__)
  48.     "COMPACT"
  49. #else
  50. #if defined(__SMALL__)
  51.     "SMALL"
  52. #else
  53. #if defined(__TINY__)
  54.     "TINY"
  55. #else
  56.     "**UNKNOWN**"
  57. #endif
  58. #endif
  59. #endif
  60. #endif
  61. #endif
  62. #endif
  63.     );
  64.  
  65.     if(!XMS_Setup()) {  /* must be called before using any other XMS function */
  66.         printf("There seems to be no XMS driver installed!\n");
  67.         exit(1);
  68.     }
  69.     XMS_Version(&ver_proto, &ver_driver, &hma_avail);
  70.     printf("XMS Status:  Protocol version: %x  Internal version: %x  HMA avail: %s\n",
  71.                 ver_proto, ver_driver, hma_avail ? "Yes" : "No");
  72.     if(ver_proto!=0x0200) {
  73.         printf("Protocol version is NOT 2.00, so I'm gonna FREAK!\n");
  74.         exit(1);
  75.     }
  76.     printf("%x returned from XMS_FreeMem(...)\n",XMS_FreeMem(&freemem,&totmem));  /* query free XMS memory */
  77.     printf("XMS Status:  %dk total, %dk total\n", totmem, freemem);
  78.     printf("Allocate HMA: %x\n",XMS_RequestHMA(0xffff));
  79.     printf("Release HMA: %x\n",XMS_ReleaseHMA());
  80.     printf("GlobalDisableA20: %x :",XMS_GlobalDisableA20());
  81.  
  82.     XMS_QueryA20(&state);
  83.     printf("A20 state: %s\n",state ? "Enabled" : "Disabled");
  84.     printf("LocalEnableA20: %x :",XMS_LocalEnableA20());
  85.  
  86.     XMS_QueryA20(&state);
  87.     printf("A20 state: %s\n",state ? "Enabled" : "Disabled");
  88.     printf("LocalDisableA20: %x :",XMS_LocalDisableA20());
  89.  
  90.     XMS_QueryA20(&state);
  91.     printf("A20 state: %s\n",state ? "Enabled" : "Disabled");
  92.  
  93.     error = XMS_AllocEMB(10,&handle); /* allocate 10k of memory */
  94.     printf("AllocEMB: %x   handle: %x\n",error, handle);
  95.  
  96. /* next, copy our little message to extended memory */
  97.     moverec.TransferLength = sizeof(message);
  98.     moverec.SourceHandle = 0;   /* handle of 0 means direct memory */
  99.     moverec.SourceOffset = (unsigned long)message;
  100.     moverec.DestHandle = handle;    /* our EMB handle */
  101.     moverec.DestOffset=0;   /* copy to the front of the block */
  102.     error = XMS_MoveEMB(&moverec);
  103.     printf("MoveEMB: %x\n",error);
  104.     printf("String 1: %s\nString 2: %s\n",message, message2);
  105.  
  106.     moverec.TransferLength = sizeof(message);   
  107.     moverec.DestHandle = 0;            /* now, move it to the second string */
  108.     moverec.DestOffset = (unsigned long)message2;
  109.     moverec.SourceHandle = handle;
  110.     moverec.SourceOffset=0;
  111.     error = XMS_MoveEMB(&moverec);
  112.     printf("MoveEMB: %x\n",error);
  113.     printf("String 1: %s\nString 2: %s\n",message, message2);
  114.  
  115.     error = XMS_LockEMB(handle, &address);
  116.     printf("Handle %x located at linear memory address %lx\n",handle, address);
  117.     printf("Lock returned error %x\n",error);
  118.  
  119.     error = XMS_ReallocEMB(handle, 20); /* reallocate as 20k instead of 10 */
  120.     printf("ReallocEMB: %x\n",error);   /* THIS SHOULD FAIL BECAUSE OF LOCK */
  121.  
  122.     error = XMS_GetEMBHandleInfo(handle, &locks, &fhandles, &blength);
  123.     printf("Info on handle %x: Locks: %d Free handles: %d Block length: %d\n",
  124.         handle, locks, fhandles, blength);
  125.  
  126.     error = XMS_UnlockEMB(handle);
  127.     printf("Unlock returned error %x\n",error);
  128.  
  129.     error = XMS_ReallocEMB(handle, 20); /* reallocate as 20k instead of 10 */
  130.     printf("ReallocEMB: %x\n",error);
  131.  
  132.     error = XMS_GetEMBHandleInfo(handle, &locks, &fhandles, &blength);
  133.     printf("Info on handle %x: Locks: %d Free handles: %d Block length: %d\n",
  134.         handle, locks, fhandles, blength);
  135.  
  136.     error = XMS_FreeEMB(handle); /* free memory */
  137.     printf("FreeEMB: %x\n",error);
  138.  
  139.     error = XMS_RequestUMB(0xffff, &segaddr, &maxumb);
  140.     printf("RequestUMB: %x  MaxSize: %d\n",error, maxumb);
  141.  
  142.     return 0;
  143. }
  144.